config: load and validate generated config models#4898
config: load and validate generated config models#4898MikeGoldsmith wants to merge 24 commits intoopen-telemetry:mainfrom
Conversation
Proposing that the first step towards implementing OpenTelemetry Configuration is to produce the model code from the json schema. I did a quick search for tools available to do this and came across datamodel-codegen which seems to do what i expected. Will open following pull requests (in draft) to use this model code, i just want to keep these as clearly separated as possible to make reviewing them easier. Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com>
… into codeboten/generate-config-model-from-schema
…ate-config-model-from-schema fix code-generation command and regenerate models
…ate-config-model-from-schema.2 Fix lint errors and update uv.lock file
Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com>
… into codeboten/generate-config-model-from-schema
…com:codeboten/opentelemetry-python into mike/otel-config/1-loading-validation
datamodel-codegen section was inserted between [tool.pyright] and its include/exclude config, causing pyright to check entire repo (599 files) instead of just included paths. Moved datamodel-codegen section after pyright config.
…com:codeboten/opentelemetry-python into mike/otel-config/1-loading-validation
- Fix re.sub callback return type (must return str, not str | None) - Rename DOLLAR_PLACEHOLDER to dollar_placeholder (pylint naming) - Rename f to temp_file/config_file (pylint naming) - Update uv.lock
Fixes yaml import warning by installing PyYAML type stubs and the file-configuration optional dependencies.
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
Assisted-by: Claude Sonnet 4.6
- Bundle schema.json (v1.0.0-rc.3) alongside models.py - Add jsonschema >= 4.0 to file-configuration optional extra - Validate parsed config against schema before constructing model, with field path included in error messages for nested violations - Switch datamodel-codegen to use local schema (drop [http] extra) - Add schema validation tests (wrong type, missing required, nested path, enum violation) Assisted-by: Claude Sonnet 4.6
b22fc34 to
9778ae5
Compare
- Replace global statement with list cache in _get_schema - Extract _validate_schema helper to reduce branches/statements in load_config_file Assisted-by: Claude Sonnet 4.6
jsonschema's `referencing` dep uses TypeVar defaults which requires typing_extensions>=4.12.0 on Python 3.13+ (4.10.0 raises AttributeError on TypeVar.__default__). Assisted-by: Claude Sonnet 4.6
|
Thank you for this @MikeGoldsmith ! I'm new to The local schema copy is nice for performance. Is this something to semi-automatically manage later, kinda like the semconvgen? Once this gets merged, is this correct?: There's mention of |
Description
The next step of implementing configuration file support. This PR loads and validates the generated config models. Using the model to configure the SDK will come in later PRs.
Based on the following PR which added model generation from the schema:
Contributes to:
Type of change
Changes
jsonschema >= 4.0to thefile-configurationoptional extratyping_extensionspin to4.12.0in test requirements for Python 3.13+ compatibility (referencing, a transitive dep ofjsonschema, uses TypeVar defaults which require this version)How Has This Been Tested?
36 unit tests covering file loading, parsing (YAML/JSON), env substitution, and schema validation.
Does This PR Require a Contrib Repo Change?
Checklist: